<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>#!命令</title>
</head>
<body>
    <h1>#!命令</h1>
    <h2>为JavaScript脚本引入命令行执行器</h2>

    <script>
        // 示例脚本（script.js）
        /*
        #!/usr/bin/env node
        console.log('Hello from Node.js!');
        */

        // 实际应用示例
        // 1. CLI工具
        /*
        #!/usr/bin/env node
        const program = require('commander');

        program
            .version('0.1.0')
            .option('-p, --port <number>', '指定端口号')
            .option('-h, --host <string>', '指定主机名')
            .parse(process.argv);

        const options = program.opts();
        console.log('启动服务器:', options.host, options.port);
        */

        // 2. 构建脚本
        /*
        #!/usr/bin/env node
        const { build } = require('esbuild');

        build({
            entryPoints: ['src/index.js'],
            bundle: true,
            outfile: 'dist/bundle.js',
        }).catch(() => process.exit(1));
        */

        // 3. 数据处理脚本
        /*
        #!/usr/bin/env node
        const fs = require('fs').promises;
        const path = require('path');

        async function processFiles(dir) {
            const files = await fs.readdir(dir);
            for (const file of files) {
                if (path.extname(file) === '.json') {
                    const content = await fs.readFile(
                        path.join(dir, file), 
                        'utf8'
                    );
                    // 处理数据...
                }
            }
        }

        processFiles(process.argv[2]).catch(console.error);
        */

        // 4. 自动化测试
        /*
        #!/usr/bin/env node
        const { runTests } = require('./test-runner');

        async function main() {
            try {
                const results = await runTests();
                console.log('测试结果:', results);
                process.exit(results.failed ? 1 : 0);
            } catch (error) {
                console.error('测试执行失败:', error);
                process.exit(1);
            }
        }

        main();
        */
    </script>
</body>
</html> 